﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PefStudio.Windows;

namespace PefStudio.Windows.Menus
{
    [Export(MainWindow.MainMenuContract, typeof(IMenuItem))]
    sealed class MainFileMenu : AbstractMenuItem, IPartImportsSatisfiedNotification
    {
        public const string Contract = "PefStudio.Windows.MainMenu.FileMenu";

        public MainFileMenu()
        {
            ID = "File";
            Text = "&File";
            Index = 1.0;
        }

        [ImportMany(Contract, typeof(IMenuItem), AllowRecomposition = true)]
        private IEnumerable<IMenuItem> MenuItems { get; set; }

        public void OnImportsSatisfied()
        {
            CreateService.CreateMenu(this.DropDownItems, MenuItems, MainWindow);
        }
    }

    [Export(MainFileMenu.Contract, typeof(IMenuItem))]
    sealed class MainFileMenuExit : AbstractMenuItem
    {
        public MainFileMenuExit()
        {
            ID = "Exit";
            Text = "E&xit";
            ShortcutKeys = Keys.Alt | Keys.F4;
            HasSeparator = true;
        }

        protected override void OnClick(EventArgs e)
        {
            MainWindow.Close();
        }
    }
}
